package com.gable.exhibition.init;

import com.alibaba.fastjson.JSON;
import com.gable.exhibition.dao.ManufacturerSupplierDao;
import com.gable.exhibition.view.ManufacturerSupplierView;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by mj on 2018/3/16.
 * 供应商厂商关系初始化类
 */
@Component
public class SupplierManufacturerInit {

    Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    ManufacturerSupplierDao manufacturerSupplierDao;

    public static Map<Long,ManufacturerSupplierView> supplierManufacturerMap = null;  //供应商厂商关系

    public void querySupplierManufacturer(){
        logger.debug("经销商和厂商之间的关系初始化开始");
        if(supplierManufacturerMap == null){
            supplierManufacturerMap = new HashMap<Long,ManufacturerSupplierView>();
        }

        List<ManufacturerSupplierView> list =  manufacturerSupplierDao.supplierManufacturerInit();
        for(ManufacturerSupplierView ms : list){
            Long supplierId = ms.getSupplierId();
            supplierManufacturerMap.put(supplierId,ms);
        }
        logger.debug("经销商和厂商之间的关系初始化结束");
        logger.debug("结果集："+ JSON.toJSONString(supplierManufacturerMap));
    }
}
